﻿using System;
using System.Web;

namespace KPIS.GERP.Models.Class
{
    public static class BrowserVersion
    {
        public static bool IsIe
        {
            get
            {
                return UserAgent.ContainsAnyCaseInsensitive("MSIE", "rv:");
            }
        }

        public static int? IeVersion
        {
            get
            {
                if (IsIe11) return 11;
                if (IsIe10) return 10;
                if (IsIe9) return 9;
                if (IsIe8) return 8;
                if (IsIe7) return 7;
                if (IsIe6) return 6;
                return null;
            }
        }

        public static string UserAgent { get { return HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"] ?? string.Empty; } }
        public static bool IsIe11 { get { return UserAgent.ContainsAnyCaseInsensitive("rv:11.0"); } }
        public static bool IsIe10 { get { return UserAgent.ContainsAnyCaseInsensitive("MSIE 10.0;"); } }
        public static bool IsIe9 { get { return UserAgent.ContainsAnyCaseInsensitive("MSIE 9.0;"); } }
        public static bool IsIe8 { get { return UserAgent.ContainsAnyCaseInsensitive("MSIE 8.0;"); } }
        public static bool IsIe7 { get { return UserAgent.ContainsAnyCaseInsensitive("MSIE 7.0;"); } }
        public static bool IsIe6 { get { return UserAgent.ContainsAnyCaseInsensitive("MSIE 6.0;"); } }
        public static bool IsMobile { get { return UserAgent.ContainsAnyCaseInsensitive("mobile"); } }
        public static bool IsXBoxOne { get { return UserAgent.ContainsAnyCaseInsensitive("Xbox One"); } }
        public static bool IsXBox360 { get { return !IsXBoxOne && UserAgent.ContainsAnyCaseInsensitive("Xbox"); } }
        public static bool IsChrome { get { return UserAgent.ContainsAnyCaseInsensitive("Chrome"); } }
        public static bool IsFirefox { get { return UserAgent.ContainsAnyCaseInsensitive("Firefox"); } }
        public static bool IsOpera { get { return UserAgent.ContainsAnyCaseInsensitive("OPR"); } }
        public static bool IsSafari { get { return !IsChrome && UserAgent.ContainsAnyCaseInsensitive("Safari"); } }
    }
}